//package com.douqu.game.main.merge;
//
//import com.douqu.game.core.database.model.GMLogModel;
//import com.douqu.game.core.database.model.GMModel;
//import com.douqu.game.core.util.CoreUtils;
//import com.douqu.game.core.util.LogUtils;
//
//import java.util.ArrayList;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
///**
// * @Author: Bean
// * @Description:
// * @Date: 2018-03-24 15:31
// */
//public class MergeMain {
//
//
//    public static void main(String[] args)
//    {
////        LoadFactory.loadGameObject("data");
////
////        merge(new DatabaseConfig("192.168.2.228", "3306", "slg1", "root", "123456"),
////                new DatabaseConfig("192.168.2.228", "3306", "slg1002", "root", "123456"),
////                new DatabaseConfig("192.168.2.228", "3306", "slg1003", "root", "123456"),
////                new DatabaseConfig("192.168.2.228", "3306", "slg1004", "root", "123456"));
////        System.exit(0);
//
//
//    }
//
//
//
//    public static void merge(DatabaseConfig saveDatabaseConfig, DatabaseConfig... readDatabaseConfig)
//    {
//        DatabaseFactory saveDatabase = new DatabaseFactory(saveDatabaseConfig);
//        int playerCount = saveDatabase.getRealPlayerCount();
//        if(playerCount > 0)
//        {
//            LogUtils.info("请先清空最终数据库");
//            return;
//        }
//        List<MergePlayer> mergePlayerList = new ArrayList<>();
//        List<GMLogModel> gmLogModelList = new ArrayList<>();
//        List<GMModel> gmModelList = new ArrayList<>();
//        DatabaseFactory readDatabase = null;
//
//        for(DatabaseConfig databaseConfig : readDatabaseConfig)
//        {
//            LogUtils.info("开始读取数据库 -> " + databaseConfig.getHost() + ":" + databaseConfig.getPort() + "/" + databaseConfig.getDb());
//            readDatabase = new DatabaseFactory(databaseConfig);
//            List<MergePlayer> tempList = readDatabase.getPlayerList();
//            LogUtils.info("玩家数量 -> " + tempList.size());
//            mergePlayerList.addAll(tempList);
//
//            gmLogModelList.addAll(readDatabase.getGMLogList());
//            List<GMModel> list = readDatabase.getGMList();
//            for(GMModel gmModel : list)
//            {
//                if(gmModelList.contains(gmModel))
//                    continue;
//
//                gmModelList.add(gmModel);
//            }
//        }
//
//        Map<String, MergePlayer> userModelMap = new HashMap<>();
//        int i = saveDatabase.getRobotCount() + 1;
//        MergePlayer tempPlayer = null;
//        List<MergePlayer> finalPlayerList = new ArrayList<>();
//        for(MergePlayer mergePlayer : mergePlayerList)
//        {
//            tempPlayer = userModelMap.get(mergePlayer.getUserModel().getAccount());
//            if(tempPlayer != null)
//            {
//                if(CoreUtils.isNullOrEmpty(tempPlayer.getUserModel().getMobile()) && !CoreUtils.isNullOrEmpty(mergePlayer.getUserModel().getMobile()))
//                    tempPlayer.getUserModel().setMobile(mergePlayer.getUserModel().getMobile());
//
//                tempPlayer.getPlayerList().addAll(mergePlayer.getPlayerList());
//            }
//            else
//            {
//                mergePlayer.setId(++i);
//                finalPlayerList.add(mergePlayer);
//                userModelMap.put(mergePlayer.getUserModel().getAccount(), mergePlayer);
//            }
//        }
//
//
//        LogUtils.info("开始合并数据库 -> 最终玩家数量 -> " + finalPlayerList.size() + ",GM日志记录数量 -> " + gmLogModelList.size());
//
//        saveDatabase.merge(finalPlayerList, gmLogModelList, gmModelList);
//
//        LogUtils.info("数据库合并成功 --------------------------------> ");
//    }
//
//}
